$(document).ready(function () {   
    var userid = jQuery.url.param("userid");
    if (userid) {
        $.get("/user/" + userid, function (data, status) {
            alert(data.nickname);
        });
    }
    var containerHeight = document.body.clientHeight;
    var containerWidth = document.body.clientWidth;
    $("#indexContainer img").each(function () {
        $(this).css("height", containerHeight);
        $(this).css("width", containerWidth);
    });
    $("#indexContainer").css("height", containerHeight);
    
    var swiper1 = new Swiper('#indexContainer', {
        /*pagination: '#indexPagination',*/
        paginationClickable: true,
        spaceBetween: 30,
    });
    var swiper2 = new Swiper('#mainContainer', {
        /*pagination: '.swiper-pagination',*/
        paginationClickable: '.swiper-pagination',
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
        spaceBetween: 30
    });
    
    
    function MyController(){
        this.showMainHandler = function(evt,ui){
            if(ui.toPage.attr("id") === "main"){
                var headerHeight = $("#headerMain").height();
                var footerHeight = $("#footerMain").height();
                var containerHeight = document.body.clientHeight - headerHeight - footerHeight - 4;
                $("#mainContainer").css("height",containerHeight);
                swiper2.update();
            }else if(ui.toPage.attr("id") === "detail"){
                var headerHeight = $("#headerDetail").height();
                var footerHeight = $("#footerDetail").height();
                var containerHeight = document.body.clientHeight - headerHeight - footerHeight - 4;
                $("#detailContainer").css("height",containerHeight);
            }
            
        };
        this.sliders = [{"img":"../images/slider01.jpg"},{"img":"../images/slider02.jpg"},{"img":"../images/slider03.jpg"}];
        this.goods = [];
        this.selectedGood = undefined;
        var self = this;            
        $.getJSON('../config/goods.json',function(result){
            self.goods = result;
            for(var i=0;i<self.goods.length;i++){
                self.goods[i].drilldown = function(){
                    self.selectedGood = this;
                }
            }

        });
    }
    var uku = new Ukulele();
    uku.registerController("myCtrl", new MyController());
    uku.refreshHandler(function(){
        swiper1.update();
        swiper2.update();
    });
    uku.init();
});